package com.dyz.leetcode._01_array;

import java.util.ArrayList;
import java.util.List;

public class _163_findMissingRanges {
    public List<String> findMissingRanges(int[] nums, int lower, int upper) {
        List<String> res  = new ArrayList<>();
        //[0,2,3,4,6,7,9,19] -1 99
        //开头第一个处理 lower
        long pre = lower-1;
        for (int i=0; i<nums.length; i++){
            if(nums[i]==pre+2){
                res.add(String.valueOf(pre+1));
            }else if(nums[i]>pre+2){
                res.add((pre+1)+"->"+(nums[i]-1));
            }
            pre = nums[i];
        }
        // 结尾 upper处理, 目前pre指向nums最后一个
        if(pre+1==upper){res.add(String.valueOf(pre+1));}
        else if(upper>pre+1){
            res.add((pre + 1) + "->" + upper);
        }

        return res;
    }
}
